package tema10.controller;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet(name="FalsoFrontControllerCRUDServlet", urlPatterns={"/tema10/falsoFrontControllerCRUD"})
public class FalsoFrontControllerCRUDServlet extends BasicUtilitiesServlet {

    @Override
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
               try {
            request.setCharacterEncoding("UTF-8");
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(FalsoFrontControllerCRUDServlet.class.getName()).log(Level.SEVERE,
                    "No se pudo establecer el encoding", ex);
        }
        String form = request.getParameter("form");
        if (form == null || (persistenceMechanism != null
                && persistenceMechanism.equals("none"))) {
            request.setAttribute("operacion", "FRONT CONTROLLER");
            request.setAttribute("persistencia", persistenceMechanism);
            gotoURL(errorForm, request, response);
        } else if (form.equals("createServlet")) {
            gotoNamedResource("CreateServlet", request, response);
        } else if (form.equals("updateServlet")) {
            gotoNamedResource("UpdateServlet", request, response);
        } else if (form.equals("deleteServlet")) {
            gotoNamedResource("DeleteServlet", request, response);
        } else if (form.equals("readServlet")) {
            gotoNamedResource("ReadServlet", request, response);
        } else if (form.equals("listServlet")) {
            gotoNamedResource("ListServlet", request, response);
        } else {
            gotoURL("/EjemploBasicoJavaEE/tema8/404error.html", request, response);
        }
    }
}